package com.fishleap.loadbalance;

import java.util.List;

/**
 * @author zlg
 * 抽象类,实现地址列表为空或只有一个目标服务地址
 */
public abstract class AbstractLoadBalance implements LoadBalance {

    @Override
    public String selectServiceAddress(List<String> serviceAddresses) {
        if (serviceAddresses == null || serviceAddresses.size() == 0) {
            return null;
        }
        if (serviceAddresses.size() == 1) {
            return serviceAddresses.get(0);
        }
        // 真真做负载均衡的是 doSelect 方法
        return doSelect(serviceAddresses);
    }

    // 在同包或子父类中可调用
    protected abstract String doSelect(List<String> serviceAddresses);
}
